<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章列表</title>
    <link rel="stylesheet" href="../assets/lib/layui/css/layui.css">
    <!-- 图片裁剪 -->
    <link rel="stylesheet" href="../assets/lib/cropper/cropper.css" />
    <link rel="stylesheet" href="../assets/css/article/art_list.css">
</head>

<body>
    <div class="layui-card">
        <div class="layui-card-header">文章列表</div>
        <div class="layui-card-body">
            <!-- 筛选区 -->
            <form class="layui-form" id="form-search">
                <div class="layui-form-item layui-inline">
                    <select name="cate_id">
                </select>
                </div>
                <div class="layui-form-item layui-inline">
                    <select name="state">
                        <option value="">所有状态</option>
                        <option value="已发布">已发布</option>
                        <option value="草稿">草稿</option>
                    </select>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">筛选</button>
                </div>
            </form>
            <!-- 列表区 -->
            <table class="layui-table">
                <colgroup>
                    <col />
                    <col width="200" />
                    <col width="180" />
                    <col width="180" />
                    <col width="150" />
                    <col width="150" />
                </colgroup>
                <thead>
                    <tr>
                        <th>文章标题</th>
                        <th>文章封面图片</th>
                        <th>分类</th>
                        <th>发表时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <!-- 分页区 -->
            <div id="pageBox"></div>
        </div>
    </div>
    </div>

    <!-- 分类可选项 -->
    <script type="text/html" id="tpl-cate">
        <option value="">所有分类</option>
        {{each data}}
        <option value="{{$value._id}}">{{$value.name}}</option>
        {{/each}}
    </script>

    <!-- 文章列表 -->
    <script type="text/html" id="tpl-table">
        {{each data}}
        <tr>
            <td>{{$value.title}}</td>
            <td><img alt="" id="img" authsrc="{{$value.cover_img}}"></td>
            <td>{{$value.cate_name}}</td>
            <td>{{$value.pub_date}}</td>
            <td>{{$value.state}}</td>
            <td>
                <!-- 将_id 绑到 自定义属性 data-id -->
                <button type="button" class="layui-btn layui-btn-xs btn-edit" data-id="{{$value._id}}">编辑</button>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-xs btn-delete" data-id="{{$value._id}}">删除</button>
            </td>
        </tr>
        {{/each}}
    </script>

    <!-- 修改文章 -->
    <script type="text/html" id="dialog-edit">
        <!-- layui-filter 用于快速填充表单 -->
        <form class="layui-form" id="form-edit" lay-filter="form-edit">
            <!-- 隐藏域 保存文章 _id的值 -->
            <input type="hidden" name="id" id="_id">
            <div class="layui-form-item">
                <label class="layui-form-label">文章标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章类别</label>
                <div class="layui-input-block">
                    <select name="cate_id" layui-verify="required" id="cateId">
                </select>
                </div>
            </div>
            <!-- 富文本编辑器 -->
            <div class="layui-form-item">
                <!-- 左侧的 label -->
                <label class="layui-form-label">文章内容</label>
                <!-- 为富文本编辑器外部的容器设置高度 -->
                <div class="layui-input-block" style="height: 400px;">
                    <!-- 重要：将来这个 textarea 会被初始化为富文本编辑器 -->
                    <textarea name="content"></textarea>
                </div>
            </div>
            <!-- 图片裁剪 -->
            <div class="layui-form-item">
                <!-- 左侧的 label -->
                <label class="layui-form-label">文章封面</label>
                <!-- 选择封面区域 -->
                <div class="layui-input-block cover-box">
                    <!-- 左侧裁剪区域 -->
                    <div class="cover-left">
                        <img id="image" src="" />
                    </div>
                    <!-- 右侧预览区域和选择封面区域 -->
                    <div class="cover-right">
                        <!-- 预览的区域 -->
                        <div class="img-preview"></div>
                        <!-- 选择封面按钮 -->
                        <button type="button" class="layui-btn layui-btn-danger" id="btnChooseImage">选择封面</button>
                        <!-- 隐藏的文章选择框 -->
                        <input type="file" id="coverFile" accept="image/jpg, image/gif,image/png, image/jpeg">
                    </div>
                </div>
            </div>
            <!-- 发布文章 -->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">发布</button>
                    <button class="layui-btn  layui-btn-primary" lay-submit lay-filter="formDemo" id="btnSave2">存为草稿</button>
                </div>
            </div>
        </form>
    </script>

    <script src="../assets/lib/layui/layui.all.js"></script>
    <script src="../assets/lib/jquery.js"></script>
    <!-- 导入模板引擎 -->
    <script src="../assets/lib/template-web.js"></script>
    <!-- 导入富文本的js 脚本 -->
    <script src="../assets/lib/tinymce/tinymce.min.js"></script>
    <script src="../assets/lib/tinymce/tinymce_setup.js"></script>
    <!-- 导入图片裁剪 js -->
    <script src="../assets/lib/cropper/Cropper.js"></script>
    <script src="../assets/lib/cropper/jquery-cropper.js"></script>

    <script src="../assets/js/baseAPI.js"></script>
    <script src="../assets/js/article/art_list.js"></script>
</body>

</html>